/*
 * The prime factors of 13195 are 5, 7, 13 and 29.
 * 
 * What is the largest prime factor of the number 600851475143 ?
 */
package pj1;

import java.math.BigInteger;
import java.util.ArrayList;

class Problem3 {
	
	static final BigInteger problem = new BigInteger("600851475143");

	public static void main(String[] args) {
		BigInteger n = problem;
		ArrayList<BigInteger> factors = new ArrayList<BigInteger>();
		BigInteger one = BigInteger.ONE;
		BigInteger i = BigInteger.ONE.shiftLeft(1);
		
		// potential factors
		while (i.compareTo(n) == 0 || i.compareTo(n) == -1) {
			// factors
			while (n.mod(i) == BigInteger.ZERO) {
				factors.add(i);
				n = n.divide(i);
			}
			i = i.add(one);
		}
		
		// return the largest prime factors
		System.out.println(factors.get(factors.size()-1).toString());
	}

}
